//
//  RLMoreAction.swift
//  RaveLand
//
//  Created by zhuxuhong on 2021/4/28.
//  Copyright © 2021 CSLY. All rights reserved.
//

import UIKit
import BWToolKit
import BWPanelKit

typealias RLMoreActionItem = RLMoreAction.Item
typealias RLMoreActionType = RLMoreAction.Cate

struct RLMoreAction {
    struct Item {
        var cate: Cate!
        var handler: BlockVoid?
    }
}

extension RLMoreAction {
    enum Cate {
        case chat,collect,collected,follow,followed
        case block,blocked,report,limits,top,delete,forward
        
        static let titles: [Self: String] = [
            .chat: "打招呼",
            .collect: "收藏",
            .collected: "取消收藏",
            .follow: "关注",
            .followed: "取消关注",
            .block: "屏蔽",
            .blocked: "取消屏蔽",
            .report: "举报",
            .delete: "删除"
        ]
        static let icons: [Self: UIImage?] = [
            .chat: UIImage(named: "more_chat"),
            .collect: UIImage(named: "more_collect"),
            .collected: UIImage(named: "more_collected"),
            .follow: UIImage(named: "more_follow"),
            .followed: UIImage(named: "more_followed"),
            .block: UIImage(named: "more_block"),
            .blocked: UIImage(named: "more_blocked"),
            .report: UIImage(named: "more_report"),
            .delete: UIImage(named: "more_delete")
        ]
        var title: String? {
            return Self.titles[self]
        }
        var icon: UIImage?{
            return Self.icons[self] ?? nil
        }
    }
}

extension RLMoreActionItem {
    /// 删除
    static func delete(momentId mid: String, completion: BlockVoid? = nil) -> Self {
        return .init(cate: .delete) {
            func deleting(){
                
            }
            Dialog.show(title: "确认删除该条动态吗？", actions: [
                .init(title: "删除", style: .destructive) {
                    deleting()
                }
            ])
        }
    }
    
    /// 拉黑/取消拉黑
    static func block(isAdded: Bool = false, targetId: String, completion: BlockVoid? = nil) -> Self {
        let cate: RLMoreActionType = isAdded ? .blocked : .block
        return .init(cate: cate) {
            
        }
    }
    
    /// 关注/取消关注
    static func follow(isAdded: Bool = false, userId: String, completion: BlockVoid? = nil) -> Self {
        let cate: RLMoreActionType = isAdded ? .followed : .follow
        return .init(cate: cate) {
            
        }
    }
    
    /// 收藏/取消收藏
    static func collect(isAdded: Bool = false, id: String, title: String, completion: BlockVoid? = nil) -> Self {
        let cate: RLMoreActionType = isAdded ? .collected : .collect
        return .init(cate: cate) {
           
        }
    }
    
    /// 打招呼
    static func chat(userId uid: String, completion: BlockVoid? = nil) -> Self {
        return .init(cate: .chat) {
            Jumper.jump(.push(.init()))
        }
    }
}
